package com.housekeeping.housekeeping.advertisingmanagement.service.impl;/*
 * @author  pyh
 * @date  2021/1/23 0023 下午 5:42
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.advertisingmanagement.dao.impl.ProductOrderDaoImpl;
import com.housekeeping.housekeeping.advertisingmanagement.entity.ProductOrder;
import com.housekeeping.housekeeping.advertisingmanagement.service.SearchPOService;
import com.housekeeping.housekeeping.advertisingmanagement.utils.PageUtil;

import java.sql.SQLException;
import java.util.List;

public class SearchPOServiceImpl implements SearchPOService {
    private ProductOrderDaoImpl podi = new ProductOrderDaoImpl();
    @Override
    public PageUtil<List<ProductOrder>> getStateList(int status, int page, int size) throws SQLException {
        PageUtil<List<ProductOrder>> pageObj = new PageUtil<>();
        List<ProductOrder> stateList = podi.getStatusList(status, (page - 1) * size, size);
        int stateCount = podi.getStatusCount(status);

        pageObj.setData(stateList);
        //设置总条数（用于返回前端进行分页效果）
        pageObj.setTotalCount(stateCount);
        //设置当前页为当前请求页
        pageObj.setCurrentPage(page);
        return pageObj;
    }

    @Override
    public PageUtil<List<ProductOrder>> getPAndSList(String phone, int status, int page, int size) throws SQLException {
        PageUtil<List<ProductOrder>> pageObj = new PageUtil<>();
        List<ProductOrder> phoneList = podi.getPhonesList(phone, status, (page - 1) * size, size);
        int stateAndPhoneCount = podi.getStatusAndPhoneCount(status, phone);

        pageObj.setData(phoneList);
        //设置总条数（用于返回前端进行分页效果）
        pageObj.setTotalCount(stateAndPhoneCount);
        //设置当前页为当前请求页
        pageObj.setCurrentPage(page);
        return pageObj;
    }
}
